package com.qinghuan.mvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @Auther: qinghuan
 * @Date: 2022/3/21 19:33
 * @Description:
 */
@Controller
@RequestMapping(value = "/hello")
public class RequestMappingController {

    /**
     * 此处的@RequestMapping注解映射请求，
     * value为必填，可以为多个（一个url只能有一个路径，一个方法可以被多个url调用）
     * method 请求方式（选填）
     *
     * @return
     */
    @RequestMapping(
            value = {"/testRequestMapping", "/test"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    public String success() {
        return "success";
    }

    @GetMapping("/testGetMapping")
    public String testGetMapping() {
        //返回success.html页面
        return "success";
    }

    /**
     * 表单不支持 Put 和 Delete ，默认改为Get处理
     *
     * @return
     */
    @RequestMapping(value = "/testPut", method = RequestMethod.PUT)
    public String testPut() {

        return "success";
    }

    /**
     * 属性params的使用
     * params = {"username"}  //必须有username字符串，前面加 !就说明不能为username
     * params数组里的条件必须同时满足
     * headers 键值对
     * headers = {"Host=localhost:8081"} 设置headers中host为8081
     *
     * @return
     */
    @RequestMapping(value = "/testParamsAndHeaders",
            params = {"username", "password!=123456"},
            headers = {"Host=localhost:8081"})
    public String testParamsAndMethods() {
        return "success";
    }

    //    @RequestMapping("/a?a/testAnt")
//    @RequestMapping("/a*a/testAnt")
    @RequestMapping("/a**a/testAnt")
    public String testAnt() {
        return "success";
    }

    @RequestMapping("testPath/{id}/{username}")
    public String testPath(@PathVariable("id") Integer id, @PathVariable("username") String name) {
        System.out.println("id:" + id + ",username:" + name);
        return "success";
    }

}
